<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文件下载器</title>
</head>
<body>
  <script type="text/javascript">
    // const { port1, port2 } = new MessageChannel()

    // const readableStream = new ReadableStream({
    //   start(controller) {
    //     port2.onmessage = (event) => {
    //       console.log('data--->', event.data)
    //       controller.enqueue(event.data)
    //     }
    //   }
    // })
    // const writableStream = new WritableStream({
    //   write(chunk) {
    //     port1.postMessage(chunk)
    //   }
    // })

    // const writer = writableStream.getWriter()
    // const reader = readableStream.getReader()

    // writer.write('Hello Word')
    // reader.read()
    //   .then(res => {
    //     console.log('res--->', res)
    //   })

    // TransformStream 的 readable writable 实例属性
    const transformStream = new TransformStream()
    const { readable, writable } = transformStream
    
    const writer = writable.getWriter()
    const reader = readable.getReader()

    writer.write('Hello word')
    reader.read()
      .then(res => {
        console.log('res--->', res)
      })

  </script>
</body>
</html>